home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / ex / ex9-2.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  679b  |  31 lines

  1. // ex9-2.c -- Incorrect handling of member
  2. //            pointers to class instances
  3.  
  4. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex9-2.c,v 3.0 90/05/15 22:46:35 kgorlen Rel $
  5.  
  6. #include "String.h"
  7.  
  8. class X {
  9.     String* s;
  10. public:
  11.     X(const char* t="")     { s = new String(t); }
  12.     ~X()                    { delete s; }
  13.     void set(const char* t) { *s = t; }
  14.     friend ostream& operator<<(ostream& strm, X& x) {
  15.         strm << *x.s;
  16.         return strm;
  17.     }
  18. };
  19.  
  20. main()
  21. {
  22.     X a = "abc";
  23.     X b = a;
  24.     X c;
  25.     c = a;
  26.     a.set("xyz");
  27.     cout << "a=" << a << endl;
  28.     cout << "b=" << b << endl;
  29.     cout << "c=" << c << endl;
  30. }
  31.